package com.xue.my.json.fastjson;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.xue.my.User;

/**   
 * @Title: FastJsonUtils.java 
 * @Package com.xue.my.json.fastjson 
 * @Description: TODO
 * @author jimmy lovelyxuehanxin@163.com   
 * @date 2013-7-27 下午3:57:26 
 */
public class FastJsonUtils {
	
	public static <T> T StringToObject(String jsonString, Class<T> clazz){
		return (T) JSON.parseObject(jsonString, clazz);
	}
	public static  String ObjectToString(Object object){
		return JSON.toJSONString(object);
		
	}
	public static void main(String[] args) {
		User user = new User();
		user.setId(111);
		user.setAddress("jintang");
		user.setName("xuehan");
		System.out.println(StringToObject(ObjectToString(user), User.class));
		
		User user1 = new User();
		user1.setId(111);
		user1.setAddress("jintang");
		user1.setName("xuehan");
		
		List<User> list = new ArrayList<User>();
		list.add(user1);
		list.add(user);
		System.out.println(StringToObject(ObjectToString(list), List.class));
	}

}
